package com.hao.statussheet.handler;

import android.os.Handler;
import android.os.Message;

/**
 * Created by hao on 16/12/4.
 */
public class ServiceSendActivityHandler {

    public static final int ON_TIME = 0;
    public static final int ON_ALL_TIME = 1;
    public static final int ON_UPDATE = 2;
    public static final int ON_STOP = 3;


    public interface OnMusicStatusListener {
        //时间返回
        void onTime(String time);

        //总时间返回
        void onAllTime(String time);

        //进度返回
        void onUpdate(int position);

        //播放结束
        void onStop();
    }

    private static OnMusicStatusListener onMusicStatusListener;

    public static void setOnMusicStatusListener(OnMusicStatusListener onMusicStatusListener) {
        ServiceSendActivityHandler.onMusicStatusListener = onMusicStatusListener;
    }

    public static Handler getHandler() {
        return handler;
    }

    public static Message obtainMessage() {
        Message message = handler.obtainMessage();
        return message == null ? new Message() : message;
    }

    private static Handler handler = new Handler() {
        @Override
        public void handleMessage(Message msg) {
            super.handleMessage(msg);
            if (onMusicStatusListener == null)
                return;
            switch (msg.what) {
                case ON_TIME:
                    onMusicStatusListener.onTime((String) msg.obj);
                    break;
                case ON_ALL_TIME:
                    onMusicStatusListener.onAllTime((String) msg.obj);
                    break;
                case ON_UPDATE:
                    onMusicStatusListener.onUpdate((int) msg.obj);
                    break;
                case ON_STOP:
                    onMusicStatusListener.onStop();
                    break;
                default:
                    break;
            }
        }
    };


}
